<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('朗读举报列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>处理状态：</p>
                                <select name="approveStatus" th:with="type=${@dict.getType('audio_approve_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>处理方法：</p>
                                <select name="approveResult" th:with="type=${@dict.getType('audio_feedback_approve_result')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <audio controls="controls" id="audio" autoplay="false">
                    <source src=""/>
                </audio>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('yuwen:yuwenfeedback:edit')}]];
        var removeFlag = [[${@permission.hasPermi('yuwen:yuwenfeedback:remove')}]];
        var approveStatusDatas = [[${@dict.getType('audio_approve_status')}]];
        var approveResultDatas = [[${@dict.getType('audio_feedback_approve_result')}]];
        var prefix = ctx + "yuwen/yuwenfeedback";
        var autioPrefix = ctx + "yuwen/yuwenaudio";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "朗读举报",
                sortName: "id",
     		    sortOrder: "desc",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'id',
                    visible: false
                },
                {
                    field : 'vid', 
                    title : '音频ID',
                    visible: false
                },
                {
                    field : 'vid',
                    title : '试听',
                    formatter: function(value, row, index) {
                       return '<a href="javascript:play(\'' + value + '\')" >试听</a>';
                    }
                },
                {
                    field : 'vid',
                    title : '打开分享页',
                    formatter: function(value, row, index) {
                       return '<a href="javascript:openShare(\'' + value + '\',' + row.id + ',' + row.approveStatus + ')" >分享页</a>';
                    }
                },
                {
                    field : 'type', 
                    title : '违规类型'
                },
                {
                    field : 'reporter', 
                    title : '举报人ID'
                },
                {
                    field : 'userStat',
                    title : '举报人统计'
                },
                {
                    field : 'createdTime', 
                    title : '举报时间'
                },
                {
                    field : 'approveStatus', 
                    title : '处理状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(approveStatusDatas, value);
                    }
                },
                {
                    field : 'approveResult', 
                    title : '处理方法',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(approveResultDatas, value);
                    }
                },
                {
                    field : 'approveTime', 
                    title : '审核时间'
                },
                {
                    field : 'approveUser', 
                    title : '审核人'
                },
                {
                    field : 'remark', 
                    title : '举报内容'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.approveStatus == 0){
                          actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="approveReporter(\'' + row.id + '\')"><i class="fa fa-edit"></i>取消审核该举报人所有举报</a> ');
                          actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="approve(\'' + row.id + '\', 1)"><i class="fa fa-edit"></i>取消审核</a> ');
                          actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="approve(\'' + row.id + '\', 2)"><i class="fa fa-edit"></i>下架并封禁</a> ');
                          actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="approve(\'' + row.id + '\', 3)"><i class="fa fa-edit"></i>没有违规</a> ');
                        }
                        //actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function play(vid){
              //var audio = document.getElementById('audio');
              //audio.src = url;
              //audio.play()
            var config = {
                url: '/yuwen/yuwenaudio/get?vid=' + vid,
                type: 'get',
                dataType: 'json',
                data: "",
                success: function(result) {
                   var audio = document.getElementById('audio');
                   audio.src = result.data.url;
                   audio.play()
                },
                error: function(err){
                   console.log(err);
                }
        	};
        	$.ajax(config)
        }

        function approve(id, approveResult) {
            var message = '';
            if(approveResult == 1){
              message = '确认取消审核该音频吗?';
            }else if(approveResult == 2){
              message = '确认下架该音频吗并封禁该上传用户吗?';
            }else if(approveResult == 3){
              message = '确认该音频不违规吗?';
            }
			$.modal.confirm(message, function() {
				$.operate.post(prefix + "/approve", { "id": id, "approveResult": approveResult });
		    })
		}

		function approveReporter(id){
           $.modal.confirm("是否批量取消审核该举报人所有举报?", function() {
				$.operate.post(prefix + "/approveReporter", { "id": id});
		   })
		}

		function openShare(vid, id, approveStatus){

		   var btn = ['取消审核', '下架并封禁', '没有违规', '关闭']
		   if(approveStatus == 1){
		      btn = ['关闭'];
		   }

		   let url = autioPrefix + `/share/${vid}`
           var width = 800;
           var height = ($(window).height() - 50);
           var index = layer.open({
                type: 2,
                area: [width + 'px', height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: '音频分享页',
                content: url,
                btn: btn,
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index){
                   if(approveStatus != 1){
                       $.operate.post(prefix + "/approve", { "id": id, "approveResult": 1 });
                   }else{
                       layer.close(index)
                   }
                },
                btn2: function(index){
                   $.operate.post(prefix + "/approve", { "id": id, "approveResult": 2 });
                },
                btn3: function(index){
                   $.operate.post(prefix + "/approve", { "id": id, "approveResult": 3 });
                },
                cancel: function(){
                   return true;
                }
            });
            layer.full(index);
		}


    </script>
</body>
</html>